using System;
using System.Data;
using System.Runtime.CompilerServices;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Channels.Tcp;
using Dimok.Data;


namespace Credit.Objects{
	/// <summary>
	/// Summary description for Clients.
	/// </summary>
	public class Clients{
		public Clients(){}

		public static string GetCreditFromEquifax(string SSN,string firstName,string lastName,string city,string state){
			return GetCreditFromEquifax(SSN,firstName,lastName,city,state,"","","");
		}
		[MethodImplAttribute(MethodImplOptions.Synchronized)]
		public static string GetCreditFromEquifax(string SSN,string firstName,string lastName,string city,string state,string SSN1,string firstName1,string lastName1){
			TcpChannel chan = new TcpChannel();
			if( city == "" || state == "" || lastName == "" || SSN1 != "" && lastName1 == "" )
				throw new CreditInquiryException("\nMissing City["+city+"] or State["+state+"] or\n\t LastName["+lastName+"] or LastName(Spouse)["+lastName1+"].\n");
			if( SSN.Length != 9 )
				throw new CreditInquiryException("\nApplicant's SSN["+SSN+"] must be 9 digits.\n");
			if( lastName1 != null && lastName1.Length > 0 && SSN1.Length != 9 )
				throw new CreditInquiryException("\nCo-Applicant's SSN["+SSN1+"] must be 9 digits.\n");
			try{
				ChannelServices.RegisterChannel(chan);
			}catch{}
			DateTime dt = DateTime.Now;
			string text = "";
			try{
				Equifax obj = (Equifax)Activator.GetObject(typeof(Equifax), Dimok.Config.Credit.equifax.RemoteUrl);
				//throw new Exception("RemoteUrl:"+Reg.RemoteUrl);
				text = obj.GetCredit(SSN,firstName,lastName,city,state,"",SSN1,firstName1,lastName1);
				TimeSpan ts = DateTime.Now.Subtract(dt);
				text = ts.Seconds.ToString()+"."+ts.Milliseconds.ToString("000")+" sec"+Environment.NewLine+text;
			}finally{
				try{
					ChannelServices.UnregisterChannel(chan);
				}catch{}
			}
			return text;
		}
	}
}
